package com.controller;

import com.pojo.Area;
import com.pojo.User;
import com.service.AreaService;
import com.service.UserService;
import com.util.Pager;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

@RestController
@RequestMapping("/base/area")
public class AreaHandler {
    @Resource
    private AreaService areaService;


    /**
     * 分页查询
     * @param area
     * @param limit
     * @param offset
     * @return pager
     * @throws UnsupportedEncodingException
     */
    @RequestMapping("/searchByAreaPager")
    public Pager<Area> searchPager(Area area, Integer limit, Integer offset){

        Pager<Area> pager =new Pager<>();
        pager.setLimit(limit);
        pager.setOffSet(offset);
        pager.setCondition(area);
        return areaService.searchByAreaPager(pager);
    }

    /**
     * 删除单个
     * @param aid
     * @return int
     */
    @RequestMapping("/delArea")
    public String deleteArea(String aid){
        String msg="删除失败！";
        int i =areaService.del(aid);
        if(i>0){
            msg="删除成功！";
        }
        return msg;
    }

    /**
     * 修改
     * @param area
     * @return
     */
    @RequestMapping("/updateArea")
    public String updateUser(Area area){
        String msg="修改失败！";
        int i = areaService.update(area);
        if(i>0){
            msg="修改成功！";
        }
        return msg;
    }

    /**
     * 添加
     * @param area
     * @return
     */
    @RequestMapping("/addArea")
    public String addUser(Area area){
        String msg="添加失败！";
        int i = areaService.add(area);
        if(i>0){
            msg="添加成功！";
        }
        return msg;
    }

}
